//package com.infra.server.service;
//
//import com.alibaba.fastjson.JSONObject;
//import com.infra.server.entity.SysLog;
//import com.infra.server.utils.ConstantUtil;
//import com.infra.server.utils.EsUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.elasticsearch.common.xcontent.XContentBuilder;
//import org.elasticsearch.common.xcontent.XContentFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.stereotype.Component;
//
///**
// * @author win
// * @date 2021/9/13 9:16
// */
//@Slf4j
//@Component
//public class AsyncTask {
//
//    @Autowired
//    private EsUtil esUtil;
//
//    /**
//     * 保存记录到es
//     */
//    @Async
//    public void saveES(SysLog sysLog) {
//        try {
//            if (esUtil.existIndex(ConstantUtil.ELASTIC_USER_RECORD)) {
//                esUtil.insertDocument(ConstantUtil.ELASTIC_USER_RECORD,"", JSONObject.toJSONString(sysLog));
//            } else {
//                XContentBuilder xContentBuilder = XContentFactory.jsonBuilder()
//                        .startObject()
//                        .startObject("properties")
//                        .startObject("createTime")
//                        .field("type","date")
//                        .endObject()
//                        .endObject()
//                        .endObject();
//                boolean a = esUtil.createIndex(ConstantUtil.ELASTIC_USER_RECORD,xContentBuilder);
//                if (a) {
//                    esUtil.insertDocument(ConstantUtil.ELASTIC_USER_RECORD,"",JSONObject.toJSONString(sysLog));
//                }
//            }
//        } catch (Exception e) {
//            log.error("记录用户操作记录异常：{}",e.getMessage());
//        }
//    }
//}
